<?php
if(!defined('ADMIN')){
	exit('Access Denied');
}

$code=empty($_POST['code'])?0:$_POST['code'];
$jine = empty($_POST['jine'])?0:(int)$_POST['jine'];
if(empty($code))
{
    die('-1');//验证码为空
}
if(empty($jine))
{
    die('-5');//订单金额为空
}
$sql = "select a.coupon_sn,a.status as stat,b.* from ce_coupon_given as a left join ce_card_coupon as b on (a.coupon_id = b.id) where coupon_sn='".$code."' ";
//echo $sql;
$query = $ezhand->query($sql);
$ret = $ezhand->fetch_array($query);
//var_dump($ret);
if(empty($ret))
{
    die('-2');//无此优惠劵
}

if($ret['stat'] == 1)
{
    die('-3');//已用过
}
$curtime = time();
if($curtime<$ret['starttime'] || $curtime > $ret['endtime'])
{
    die('-4');//优惠劵已过期
}
if($jine < $ret['spendmoney'])
{
    die('-6');//未达到最低消费
}
die(''.$ret['money'].'');
?>